package rpc.registry.zookeeper;

import org.apache.curator.framework.CuratorFramework;
import rpc.registry.ServiceRegistry;
import rpc.registry.zookeeper.utils.CuratorUtils;

import java.net.InetSocketAddress;

/**
 * @ClassName: ZkServiceRegistryImpl
 * @Description: 将服务注册到Zookeeper中
 * @author: Kowk
 * @since:1.0.0
 */
public class ZkServiceRegistryImpl implements ServiceRegistry {
    @Override
    public void registerService(String rpcServiceName, InetSocketAddress inetSocketAddress) {
        String servicePath = CuratorUtils.ZK_REGISTER_ROOT_PATH + "/" + rpcServiceName + inetSocketAddress.toString();
        CuratorFramework zkClient = CuratorUtils.getZkClient();
        CuratorUtils.createPersistentNode(zkClient,servicePath);
    }
}
